package com.rd.student.jike.class2.lihongming.StudentSystem;

import java.util.Objects;

/**
 * @Auther:Heinrich
 * @Date:2023/7/12-07-12-12:05
 * @Description:com.rd.student.jike.class2.lihongming.StudentSystem
 * @version:1.0
 */
public class StudentG4 implements Comparable{
    static int ORDER = 1;
    private int studentId;
    private String name;
    private String major;
    private String cls;
    private String desc;
    private Integer age;

    private int codeNum;

    public int getID(){
        return studentId;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name == null || name == "") {
            System.out.println("学生姓名不允许为空");
        } else {
            this.name = name;
        }

    }

    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        if (major == null || major == "") {
            System.out.println("学生专业不允许为空");
        } else {
            this.major = major;
        }

    }

    public String getCls() {
        return cls;
    }

    public void setCls(String cls) {
        if (cls == null || cls == "") {
            System.out.println("学生班级不允许为空");
        } else {
            this.cls = cls;
        }
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age < 0 || age > 120) {
            System.out.println("学生年龄不符合规范");
        } else {
            this.age = age;
        }

    }

    public StudentG4() {
        this.studentId = ORDER++;
    }
    public StudentG4(String name, String dept, String cla, String comment, int age,int codeNum) {
        this.name = name;
        this.major = dept;
        this.cls = cla;
        this.desc = comment;
        this.age = age;
        this.studentId = ORDER++;
        this.codeNum = codeNum;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        StudentG4 studentG4 = (StudentG4) o;
        return studentId == studentG4.studentId && age == studentG4.age && name.equals(studentG4.name) && major.equals(studentG4.major) && cls.equals(studentG4.cls) && Objects.equals(desc, studentG4.desc);
    }

    @Override
    public int hashCode() {
        return Objects.hash(studentId, name, major, cls, desc, age);
    }

    @Override
    public String toString() {
        return   "学号：" + studentId +
                ",姓名：" + name +
                ", 专业：" + major +
                ", 班级：" + cls +
                ", 描述：" + desc +
                ", 年龄：" + age +
                ",代码量" + codeNum;
    }


    @Override
    public int compareTo(Object o) {
        StudentG4 s = (StudentG4) o;
        if (s.getAge() > this.age) {
            return -1;
        } else if (s.getAge() < this.age) {
            return 1;
        }
        return 0;
    }
}
